package com.sca.bussiness.controller;

import com.sca.bussiness.entity.api.BaseResult;
import com.sca.bussiness.entity.enums.ResultEnum;
import com.sca.bussiness.service.LockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author liuxianfei
 * @since 2020/11/23 11:10
 */
@Api
@RestController
@RequestMapping("/bussiness/v1/lock")
public class LockController {

    private final LockService lockService;

    public LockController(LockService lockService) {
        this.lockService = lockService;
    }

    @GetMapping("/zk")
    @ApiOperation("zookeeper分布式锁")
    public BaseResult<?> zk() {
        if (lockService.zookeeperLock()) {
            return new BaseResult<>();
        }
        return new BaseResult<>(ResultEnum.ERR);
    }

    @GetMapping("/redis")
    @ApiOperation("redis分布式锁")
    public BaseResult<?> redis() {
        if (lockService.redisLock()) {
            return new BaseResult<>();
        }
        return new BaseResult<>(ResultEnum.ERR);
    }

}
